(* ================================================== *)
(* lexer pour l'analyse syntaxique d'un fichier mop  *)
(* author Mathieu Barbin                              *)
(* version samedi 3 janvier 2009, 11:27:58 (UTC+0100) *)
(* ================================================== *)

{ 
  open MopTypes
  open ParserMop
    
  let count_next = function
    | '\n' -> incr(mop_line)
    | _ -> ()
}

rule lexem_list = parse
  | (['/'] ['*'] ([^'*'] | (['*'] [^'/']))* 
       ['*'] ['/']) as code                      { for i = 0 to pred (String.length code) do count_next code.[i] done; 
						   lexem_list lexbuf }  
  | (['/'] ['/'] [^'\n']* ['\n'])                { incr(mop_line); 
						   lexem_list lexbuf }
  | ['\n']                                       { incr(mop_line);
						   lexem_list lexbuf }
  | [' ' '\t'] +                                 { lexem_list lexbuf }
  | "define"                                     { DEFINE }
  | "#include"                                   { TAG_INCLUDE }
  | "with"                                       { WITH }
  | "map"                                        { MAP }

  | (['$'] ['0'-'9']+) as entier                 
      {
	let len = String.length entier in
	let ve = String.sub entier 1 (len - 1) in
	ARG (int_of_string ve)
      }
  | (['0'-'1' '*']+) as partial                  { PARTIAL partial }
  | "|"                                          { BARRE }
  | "->"                                         { FLECHE }
  | (['A'-'Z' 'a'-'z' '_'] 
       ['A'-'Z' 'a'-'z' '0'-'9' '_']* 
          ['*']?)
      as name                                    { (* print_string "Ident : "; print_endline name;*) IDENT name }
  | (['\"'] [^'\"']* ['\"']) as chaine           
      {
	let len = String.length chaine in
	(*	print_string "String : "; print_endline chaine; *)
	STRING (String.sub chaine 1 (len - 2))
      } 
  
  | (['A'-'Z' 'a'-'z' '_'] 
       ['A'-'Z' '[' ']' ':' '.' 'a'-'z' '0'-'9' '_']* 
       ['*']?)
      as name                                    { (* print_string "Net Ident : "; print_endline name;*) NET_IDENT name }    
  | eof  { EOF }
